<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2008 XBRL International. All Rights Reserved. -->
<?xml-stylesheet type="text/xsl" href="../stylesheets/conformanceFunction.xsl"?>
<testcase
  xmlns="http://xbrl.org/2008/conformance"
  xmlns:reg="http://xbrl.org/2008/registry"
  xmlns:fcn="http://xbrl.org/2008/function"
  xmlns:cfcn="http://xbrl.org/2008/conformance/function"
  xmlns:xbrli="http://www.xbrl.org/2003/instance"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xfi="http://www.xbrl.org/2008/function/instance"
  xmlns:xfie="http://www.xbrl.org/2008/function/instance/error"
  xmlns:xqt-err="http://www.w3.org/2005/xqt-errors"
  xmlns:concept="http://xbrl.org/formula/conformance/example" 
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xsi:schemaLocation="
  http://xbrl.org/2008/registry ../schemas/registry.xsd
  http://xbrl.org/2008/function ../schemas/function.xsd
  http://xbrl.org/2008/conformance ../schemas/conformance.xsd
  http://xbrl.org/2008/conformance/function ../schemas/conformanceFunction.xsd
  ">
  <owners>
    <reg:owner id="herm">
      <reg:name>Herm Fischer</reg:name>
      <reg:affiliation>UBMatrix / Mark V Systems</reg:affiliation>
      <reg:email>fischer@markv.com</reg:email>
     <reg:assumedOwnership moment="2008-02-19T00:00:00" />
    </reg:owner>
  </owners>

  <number>90102</number>

  <name>Function test xfi:items-in-instance</name>

  <documentation>
    <xhtml:p>
      Tests of xfi:items-in-instance($instance as element(xbrli:xbrl)) as schema-element(xbrli:item)*
    </xhtml:p>
  </documentation>

  <variation id="V-01">
    <name>Works for an instance with one fact.</name>
    <documentation>
      <xhtml:p>
        Tests that the function returns the correct facts for an instance with one fact.
      </xhtml:p>
     </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="facts-in-instance.xsd"/>
      <instance readMeFirst="true" id="V01" xlink:type="simple" xlink:href="one-fact-instance.xml"/>
      <cfcn:call file="V01">
        xfi:items-in-instance(/xbrli:xbrl)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 1 and
         local-name( $result ) eq 'c1' and
         $result instance of element(concept:c1,xs:string) and
         data( $result ) instance of xs:string and
         namespace-uri( $result ) eq 'http://xbrl.org/formula/conformance/example'
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-02">
    <name>Works for an instance with no facts.</name>
    <documentation>
      <xhtml:p>
        Tests that the function returns the correct facts for an instance with no facts.
      </xhtml:p>
     </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="facts-in-instance.xsd"/>
      <instance readMeFirst="true" id="V02" xlink:type="simple" xlink:href="empty-instance.xml"/>
      <cfcn:call file="V02">
        xfi:items-in-instance(/xbrli:xbrl)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 0
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-03">
    <name>Works for an instance with several facts.</name>
    <documentation>
      <xhtml:p>
        Tests that the function returns the correct facts for an instance with one fact.
      </xhtml:p>
     </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="facts-in-instance.xsd"/>
      <instance readMeFirst="true" id="V03" xlink:type="simple" xlink:href="three-fact-instance.xml"/>
      <cfcn:call file="V03">
        xfi:items-in-instance(/xbrli:xbrl)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 3 and
         local-name($result[1]) eq 'c1' and
         namespace-uri($result[1]) eq 'http://xbrl.org/formula/conformance/example' and
         local-name($result[2]) eq 'c1' and
         namespace-uri($result[2]) eq 'http://xbrl.org/formula/conformance/example' and
         local-name($result[3]) eq 'c1' and
         namespace-uri($result[3]) eq 'http://xbrl.org/formula/conformance/example' and
         (every $node in $result satisfies 
           $node instance of element(concept:c1,xs:string) and
           data($node) instance of xs:string)
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-04">
    <name>Works for an instance with tuples.</name>
    <documentation>
      <xhtml:p>
        Tests that the function returns the correct facts for an instance with tuples.  This instance includes
        nil tuples and tuples within tuples and items within tuples.
      </xhtml:p>
     </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="facts-in-instance.xsd"/>
      <instance readMeFirst="true" id="V04" xlink:type="simple" xlink:href="tuple-instance.xml"/>
      <cfcn:call file="V04">
        xfi:items-in-instance(/xbrli:xbrl)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 1 and
         local-name($result[1]) eq 'c1' and
         namespace-uri($result[1]) eq 'http://xbrl.org/formula/conformance/example' and
         data($result[1]) instance of xs:string and
         $result[1]/text() eq 'hello earthling'
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-05">
    <name>Wrong node to function</name>
    <documentation>
      <xhtml:p>
        XBRL-defined error for node type incorrect.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="facts-in-instance.xsd"/>
      <instance readMeFirst="true" id="V05" xlink:type="simple" xlink:href="one-fact-instance.xml"/>
      <cfcn:call file="V05">
        xfi:items-in-instance(//xbrli:context[1])
      </cfcn:call>
    </inputs>
    <outputs>
      <error>xqt-err:XPTY0004</error>
    </outputs>
  </variation>  

  <variation id="V-06">
    <name>Works for an instance with facts of different data types.</name>
    <documentation>
      <xhtml:p>
        Tests that the function returns the correct facts for an instance 
        and that each has proper type and PSVI atomicity type for typed operations.
      </xhtml:p>
     </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="facts-in-instance.xsd"/>
      <instance readMeFirst="true" id="V06" xlink:type="simple" xlink:href="multiple-types-instance.xml"/>
      <cfcn:call file="V06">
        xfi:items-in-instance(/xbrli:xbrl)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 4 and
         (every $node in $result satisfies 
          if ($node/@id eq 'a')
          then ($node instance of element(concept:c1,xs:string) and
                data($node) instance of xs:string)
          else if ($node/@id eq 'b') 
          then ($node instance of element(concept:i1,xs:integer) and
                data($node) instance of xs:integer and
                $node+1 eq 12346)
          else if ($node/@id eq 'c') 
          then ($node instance of element(concept:d1) and
                data($node) instance of xs:date and
                $node eq xs:date('2007-12-31'))
          else if ($node/@id eq 'd') 
          then ($node instance of element(concept:d1) and
                data($node) instance of xs:dateTime and
                $node eq xs:dateTime('2007-12-31T12:30:40'))
          else false())
      </cfcn:test>
    </outputs>
  </variation>

  <revisions>
    <reg:revision on="2008-01-30T00:00:00" by="herm">
      <xhtml:p>
        Created the test case.
      </xhtml:p>
    </reg:revision>
    <reg:revision on="2008-12-05T00:00:00" by="herm">
      <xhtml:p>
        Added variations with integer and dateUnion, added data type verification.
      </xhtml:p>
    </reg:revision>
  </revisions>
  
</testcase>

